package com.github.wisdom.member.controller;

import java.util.Arrays;
import java.util.Map;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ccssoft.m8.common.web.BaseController;
import com.github.wisdom.member.entity.IntegralconsumRuleEntity;
import com.github.wisdom.member.entity.queryEntity.PagedQueryIntegralconsumRuleEntity;
import com.github.wisdom.member.service.IntegralconsumRuleService;
import com.ccssoft.m8.common.ccssoft.modules.util.PageUtils;
import com.ccssoft.m8.common.ccssoft.modules.util.ReturnEntity;
import com.ccssoft.m8.common.ccssoft.modules.util.QueryEntityTools;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 积分消费规则配置
 *
 * @author ybg
 * @email ybg101010@163.com
 * @date 2018-09-13 21:41:33
 */
@Api(value = "积分消费规则配置",description="积分消费规则配置")
@RestController
@RequestMapping("/member/integralconsum/rules")
public class IntegralconsumRuleController extends BaseController{
    @Autowired
    private IntegralconsumRuleService<IntegralconsumRuleEntity> integralconsumRuleService;
    
    private static final String OBJECT_CODE = "${baseObjectCode}";

    /**
     * 列表
     */
    @ApiOperation("列表")
    @GetMapping("")
    public ReturnEntity<PageUtils<IntegralconsumRuleEntity>> list(PagedQueryIntegralconsumRuleEntity integralconsumRule){
    	Map<String, Object> params = QueryEntityTools.beanToMap(integralconsumRule);
		PageUtils<IntegralconsumRuleEntity> page = integralconsumRuleService.queryPage(params);
        return new ReturnEntity<PageUtils<IntegralconsumRuleEntity>>().ok(page);
    }
    
    /**
     * 列表(不分页)
     */
    @ApiOperation("列表(不分页)")
    @GetMapping("/nopage")
    public ReturnEntity<List<IntegralconsumRuleEntity>> list(IntegralconsumRuleEntity integralconsumRule){
    	Map<String, Object> columnMap = QueryEntityTools.beanToColumnMap(integralconsumRule);
		List<IntegralconsumRuleEntity> page = integralconsumRuleService.selectByMap(columnMap);
        return new ReturnEntity<List<IntegralconsumRuleEntity>>().ok(page);
    }

    /**
     * 信息
     */
    @ApiOperation("信息")
    @GetMapping("/{id}")
    public ReturnEntity<IntegralconsumRuleEntity> info(@PathVariable("id") String id){
    	IntegralconsumRuleEntity integralconsumRule = integralconsumRuleService.selectById(id);
		return new ReturnEntity<IntegralconsumRuleEntity>().ok(integralconsumRule);
    }

     /**
     * 创建
     */
    @ApiOperation("创建")
    @PostMapping("")
    public ReturnEntity<IntegralconsumRuleEntity> save(@RequestBody IntegralconsumRuleEntity integralconsumRule){
    	integralconsumRule.setId(getUUIDPrimaryKey());
		verifications(QueryEntityTools.beanToMap(integralconsumRule), OBJECT_CODE);
		integralconsumRuleService.insert(integralconsumRule);
        return new ReturnEntity<IntegralconsumRuleEntity>().ok(integralconsumRule);
    }

     /**
     * 修改
     */
    @ApiOperation("修改")
    @PutMapping("/{id}")
    public ReturnEntity<IntegralconsumRuleEntity> update(@PathVariable("id") String id,@RequestBody IntegralconsumRuleEntity integralconsumRule){
		if (id == null || id == "") {
			return new ReturnEntity<IntegralconsumRuleEntity>().error("id不能为空");
		} else {
			if (id.equals(integralconsumRule.getId())) {
			verifications(QueryEntityTools.beanToMap(integralconsumRule), OBJECT_CODE);
			integralconsumRuleService.updateById(integralconsumRule);
			return new ReturnEntity<IntegralconsumRuleEntity>().ok(integralconsumRule);
		} else {
			return new ReturnEntity<IntegralconsumRuleEntity>().error("id不匹配");
		}
						}
    }
    /**
     * 批量删除
     */
    @ApiOperation("批量删除")
    @DeleteMapping("/batch")
    public ReturnEntity delete(@RequestBody String[] ids){
		integralconsumRuleService.deleteBatchIds(Arrays.asList(ids));
    	return new ReturnEntity().ok();
    }

   /**
	 * 删除
	 */
	@ApiOperation("删除")
	@DeleteMapping("/{id}")
    public ReturnEntity delete(@PathVariable("id") String id){
		integralconsumRuleService.deleteById(id);
		return new ReturnEntity().ok();
    }

}
